//
//  orderRemarkInputViewController.m
//  SsehMaster
//
//  Created by 柳欣 on 2019/4/22.
//  Copyright © 2019 yinlong. All rights reserved.
//

#import "orderRemarkInputViewController.h"
#import "PlaceholderTextView.h"
@interface orderRemarkInputViewController ()
@property(nonatomic,strong)PlaceholderTextView *remarkInputView;
@property(nonatomic,strong)UIButton *postButton;
@end

@implementation orderRemarkInputViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self baseSetting];
    [self layoutTheUI];
}

-(void)baseSetting{
    
    self.navigationItem.title = @"备注";
    self.navigationController.navigationBar.translucent = NO;

}

-(void)layoutTheUI{
    
    self.remarkInputView = [[PlaceholderTextView alloc]initWithFrame:CGRectMake(15*PROPORTION_WIDTH_IPHONE6,25*PROPORTION_WIDTH_IPHONE6 , VIEW_WIDTH - 2*(15*PROPORTION_WIDTH_IPHONE6), 120*PROPORTION_HEIGHT_IPHONE6)];
    self.remarkInputView.placeholder = @"请输入备注";
    self.remarkInputView.maxLength  = 250;
    self.remarkInputView.text = kStringIsEmpty(self.beforeString)?@"":self.beforeString;
    self.remarkInputView.font = [UIFont systemFontOfSize:PROPORTION_HEIGHT_IPHONE6*14];
    [self.view addSubview:self.remarkInputView];
    
    self.postButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.postButton.titleLabel.font = [UIFont systemFontOfSize:16*PROPORTION_HEIGHT_IPHONE6];
    self.postButton.layer.cornerRadius = 7;
    [self.postButton setBackgroundColor:[UIColor appColor]];
    [self.postButton setTitle:@"提交" forState:UIControlStateNormal];
    [self.postButton addTarget:self action:@selector(postTheRemark:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.postButton];
    [self.postButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.remarkInputView.mas_bottom).offset(25*PROPORTION_HEIGHT_IPHONE6);
        make.left.right.equalTo(self.remarkInputView);
        make.height.mas_equalTo(47);
    }];
    
    
}

#pragma mark - - 提交备注
-(void)postTheRemark:(UIButton *)btn{

    AutoWeakSelf
    [self showTipWithTitle:@"正在提交"];
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:0];
    [dict setObject:kStringIsEmpty(self.remarkInputView.text)?@"":self.remarkInputView.text forKey:@"remark"];
    [dict setObject:self.orderID forKey:@"order_id"];
    [dict setObject:[NSString emptyStr:DEF_PERSISTENT_GET_OBJECT(SsehUserToken)] forKey:@"member_token"];
    [dict setObject:[NSString emptyStr:DEF_PERSISTENT_GET_OBJECT(SsehUserID)] forKey:@"member_id"];

    //NSString * const kServiceID = @"https://member.yinweish.com/";
    //NSString * const kOrdersServiceID = @"https://yinlong.yinweish.com/";
    
    [[QYNetManager sharedManager]POST:kUpdateMaintailOrder parameters:dict andApiTyp:SsehApiTypGetOrders SuccessBlock:^(id responseObject) {
        [weakSelf hideLoading];
        if ([responseObject[@"status"] isEqualToString:@"error"]) {
            [weakSelf showErrorTipWithTitle:responseObject[@"error"]];
        }
        else if ([responseObject[@"status"] isEqualToString:@"pending"]|| [responseObject[@"data"] isKindOfClass:[NSNull class]]){
            [weakSelf showErrorTipWithTitle:responseObject[@"error"]];
        }else{
            [weakSelf showErrorTipWithTitle:@"备注成功"];
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
    } Failure:^(NSError *error) {
        [weakSelf hideLoading];
        [weakSelf showErrorTipWithTitle:error.localizedDescription];
    }];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
